package Ajax;

import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

public class PersonalPage implements AjaxPage {
	private AjaxPage mAjaxPage = null;

	public PersonalPage(String id, HttpServletRequest request) {
		String extent = request.getParameter("extent");

		if (extent != null) {
			if (extent.equalsIgnoreCase("education")) {
				mAjaxPage = new EducationPage(id, request);
			} else if (extent.equalsIgnoreCase("award")) {
				mAjaxPage = new AwardPage(id, request);
			} else if (extent.equalsIgnoreCase("assn")) {
				mAjaxPage = new AssnPage(id, request);
			} else if (extent.equalsIgnoreCase("train")) {
				mAjaxPage = new TrainPage(id, request);
			} else if (extent.equalsIgnoreCase("experience")) {
				mAjaxPage = new ExperiencePage(id, request);
			} else if (extent.equalsIgnoreCase("language")) {
				mAjaxPage = new LanguagePage(id, request);
			} else if (extent.equalsIgnoreCase("certificate")) {
				mAjaxPage = new CertificatePage(id, request);
			} else if (extent.equalsIgnoreCase("attachment")) {
				mAjaxPage = new AttachmentPage(id, request);
			} else if (extent.equalsIgnoreCase("append")) {
				mAjaxPage = new AppendPage(id, request);
			} else if (extent.equalsIgnoreCase("forjobs")) {
				mAjaxPage = new ForjobsPage(id, request);
			} else if (extent.equalsIgnoreCase("property")) {
				mAjaxPage = new PropertyPage(id, request);
			} else if (extent.equalsIgnoreCase("iter")) {
				mAjaxPage = new IterPage(id, request);
			} else if (extent.equalsIgnoreCase("program")) {
				mAjaxPage = new ProgramPage(id, request);
			} else if (extent.equalsIgnoreCase("resumetpl")) {
				mAjaxPage = new ResumetplPage(id, request);
			}
		}
	}

	@Override
	public void printXML(PrintWriter writer) throws SQLException {
		writer.print("<?xml version=\"1.0\" encoding=\"utf-8\" ?><root><![CDATA[");

		mAjaxPage.printXML(writer);

		writer.print("]]></root>");
	}

	@Override
	public void execSql(Statement stmt, HttpServletRequest request)
			throws SQLException {
		mAjaxPage.execSql(stmt, request);
	}

	@Override
	public void printHtml(PrintWriter writer) {
		writer.print("<html><body><script language=\"javascript\" type=\"text/javascript\">parent.");
		mAjaxPage.printHtml(writer);
		writer.print(";</script></body></html>");
	}

	@Override
	public void printDel(PrintWriter writer) {
		writer.print("<html><body>");
		mAjaxPage.printDel(writer);
		writer.print(";</body></html>");
	}
}
